package com.hxh.generater.springBoot.util;


import com.hxh.entity.ProjectDatasource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnetMysql {
    Connection con;

    public Connection getConnection(ProjectDatasource projectDatasource) {
        try {
            Class.forName(projectDatasource.getMysqlDriver());
            System.out.println("数据库驱动加载成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            con = DriverManager.getConnection(projectDatasource.getMysqlConnectUrl() + "&connectTimeout=3000", projectDatasource.getMysqlUsername(), projectDatasource.getMysqlPassword());
            System.out.println("数据库连接成功");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }
}
